<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">		
 <title><? echo $title ?></title>
<? require_once("lib.php"); ?>
</head>
<body>
<div class="content-box"><!-- Start Content Box -->
  <div class="content-box-header">
      <h3><? echo $title ?></h3>
      <div class="clear"></div>
  </div> <!-- End .content-box-header -->
  <div class="content-box-content">
<?
  switch ($do) {
    case "add":
    	add();
    	break;
	case "update":
		update($info);
		break;
	case "delete":
		delete($id);
		break;
    default:
		show_info($info);
  }
 ?>
<? function show_box($row, $iseditmode, $isadd=false){ 
	global $id, $h, $cateid, $url, $title, $userid, $product, $lang, $arrlang, $arr_option, $product_option_value, $baseurl;
	?>
	<table width="99%" cellspacing="0" cellpadding="3" class="mbox">
	  <tr class="th"><td colspan="2" class="thtitle" align="right"><? echo $title ?>
      <? echo $h->hidden('id', $row["id"]);
	  		echo $h->hidden('cid', $cateid); ?></td></tr>
      <tr><td class="l"><?=ROOT_SKU?></td><td><? echo $h->text('sku', ($row["sku"]), 'gs') ?></td></tr>
	 	<?
			// array option value
			$tem = $product_option_value->get_rows(1024);
			$arr_option_value=array();
			foreach($tem as $val) $arr_option_value[$val['id']]=$val;
      $str='';
			foreach($arr_option as $key=>$val){
        $field='';
        switch ($key) {
          case 1: $field='color'; break;
          case 2: $field='size'; break;
          case 3: $field='other1'; break;
          case 4: $field='other2'; break;
        }
				$arr_tem=array();
        $arr_tem[]=array('id'=>0,'name'=>ROOT_SELECT);
				foreach($arr_option_value as $val2){
					if($val2['product_option_id']==$key) $arr_tem[]=array('id'=>$val2['id'],'name'=>$val2['name_'.$lang]);
				}
        $str.='<tr><td class="l">'.$val.'</td><td>'.$h->select($field,$row[$field],$arr_tem,'id','name','g').'</td></tr>';
			}
      echo $str;

		?>
      <tr><td class="l"><?=ROOT_PICTURE?></td><td>
      <? if(!$isadd && $row["pic"]!='')echo '<img src="'.$baseurl.'upload/'.decode($row["pic"]).'" height="72" /><br />'; ?>
      <? echo $h->cfile('cpic', 'g') ?> <span class="red"> <?=ROOT_PICTURE_SIZE_RATIO?><? echo PRODUCT_LARGE_PIC_WIDTH.':'.PRODUCT_LARGE_PIC_HEIGHT ?>.</span>
      </td></tr>
      <tr><td class="l"><?=ROOT_PRICE?></td><td><? echo $h->text('price', ($row["price"]), 'gs') ?></td></tr>
      <tr><td class="l"><?=ROOT_STOCK?></td><td><? echo $h->text('stock', ($row["stock"]), 'gs') ?></td></tr>
      <tr><td class="l"><?=ROOT_ORDER?></td><td><? echo $h->text('seq_no', ($row["seq_no"]), 'gs') ?> <span class="red"> <?=ROOT_HIGHER_NUMBER_IN_FRONT?></span></td></tr>
	  <tr><td class="l">&nbsp;</td><td><br><? echo $h->submit('save', '&nbsp; '.ROOT_SAVE.' &nbsp;', $iseditmode?'':'hide') ?>&nbsp;&nbsp;<a onClick="history.go(-1)">[ <?=ROOT_CANCEL?> ]</a><br><br></td></tr>
	</table>
<? } ?>
<? function show_boxes($result){
	global $page, $pages, $cateid, $s, $cate, $url, $h, $userid, $lang, $arr_option, $product_option_value, $baseurl;
	$str='<table width="99%" cellspacing="0" class="mlist"><tr class="th"><td><strong>#</strong></td><td><strong>'.ROOT_SKU.'</strong></td><td><strong>'.ROOT_PICTURE.'</strong></td><td><strong>'.ROOT_STOCK.'</strong></td><td><strong>'.ROOT_PRICE.'</strong></td>';
	foreach($arr_option as $val)
		$str.='<td><strong>'.$val.'</strong></td>';
	$str.='<td><strong>'.ROOT_ORDER.'</strong></td><td><strong><a href="'.$url.'.php?do=add&cid='.$cateid.'">[ '.ROOT_ADD.' ]</a></strong></td></tr>';
	$count=1;
	// array option value
	$tem = $product_option_value->get_rows(1024);
	$arr_option_value=array();
	foreach($tem as $val) $arr_option_value[$val['id']]=$val['name_'.$lang];
	foreach($result as $row)
	{
		$id=decode($row['id']);
		$tem_pic='-';
        if(!empty($row["pic"]))$tem_pic='<img src="'.$baseurl.'upload/'.decode($row["pic"]).'" height="60" />';

  		$str.="<tr><td>".$id.".</td><td><a href=\"".$url.".php?do=update&cid=".$cateid."&id=".$id."\">".d($row['sku'])."</a></td><td>".$tem_pic."</td><td>".$row['stock']."</td><td>".$row['price']."</td>";
  		foreach($arr_option as $key=>$val){
  			$field=''; $field_value='';
  			switch ($key) {
  				case 1: $field='color'; break;
  				case 2: $field='size'; break;
  				case 3: $field='other1'; break;
  				case 4: $field='other2'; break;
  			}
  			if($row[$field]==0) $field_value='-';
  			else $field_value=$arr_option_value[$row[$field]];
        $str.='<td>'.$field_value.'</td>';
  		}
  		$str.="<td>".$row['seq_no']."</td><td><a href=\"".$url.".php?do=update&cid=".$cateid."&id=".$id."\">".ROOT_UPDATE."</a> | <a href=\"$url.php?cid=".$cateid."&page=".$page."&do=delete&id=".decode($row['id'])."\" onClick=\"return delc();\">".ROOT_DELETE."</a></td></tr>";
		$count++;
	}
	$str.= "</table>";
	echo $str;
	if($count==1) echo "<br>".ROOT_NO_DATA."!";
	echo echo_page($page, $pages, $url.'-'.$cateid.'-p');
 } ?>
<br class="clear" />
	</div> <!-- End .content-box-content -->
         <br class="clear" />
</div><!-- End .content-box -->
</body>
</html>